<xsl:stylesheet version="1.0"
	xmlns:date="http://exslt.org/dates-and-times"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ms="urn:schemas-microsoft-com:xslt"
  xmlns:dt="urn:schemas-microsoft-com:datatypes"
  xmlns:ebe="http://cks/ebemethods"
  exclude-result-prefixes="date ebe">

  <xsl:output omit-xml-declaration="yes" />

  <xsl:param name="IsBlogOwner" />
  <xsl:param name="RelativeUrl" />
  <xsl:param name="Language" />
  <xsl:param name="ShortTimePattern" />
  <xsl:param name="FullDateTimePattern" />

<xsl:template match="/">
	<div class="comments">
		<h2><xsl:value-of select="ebe:res('Comments')"/></h2>
		<xsl:apply-templates select="rows/row"/>
	</div>
</xsl:template>

<xsl:template match="row">
	
	<div><xsl:attribute name="class"><xsl:choose><xsl:when test="position() mod 2 = 0">comments-author</xsl:when><xsl:otherwise>comments-visitor</xsl:otherwise></xsl:choose></xsl:attribute>
		<xsl:variable name="publishedDate" select="date:parseDate(Created, 'yyyy-MM-dd HH:mm:ss')"/>
		<span class="comments-intro">
      <xsl:value-of select="ebe:res('CommentedOn')"/>&#160;
      <xsl:value-of select="ms:format-date($publishedDate, $FullDateTimePattern, $Language)"/>&#160;
      <xsl:value-of select="ms:format-time($publishedDate, $ShortTimePattern, $Language)"/>&#160;
      <xsl:value-of select="ebe:res('CommentedBy')"/>&#160;
      <xsl:choose>
        <xsl:when test="CommentUrl != ''">
          <a>
            <xsl:attribute name="href">
              <xsl:if test="starts-with(CommentUrl, 'http') = false">
                http://
              </xsl:if>
              <xsl:value-of select="CommentUrl" />
            </xsl:attribute>
            <xsl:value-of select="Title"/>
          </a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="Title"/>
        </xsl:otherwise>
      </xsl:choose>
		</span>
		
		<p>
      <xsl:call-template name="PreserveLineBreaks">
        <xsl:with-param name="text" select="Body"/>
      </xsl:call-template>
    </p>	
	</div>
</xsl:template>

  <xsl:template name="PreserveLineBreaks">
    <xsl:param name="text"/>
    <xsl:choose>
      <xsl:when test="contains($text,'&#xA;')">
        <xsl:value-of select="substring-before($text,'&#xA;')"/>
        <br/>
        <xsl:call-template name="PreserveLineBreaks">
          <xsl:with-param name="text">
            <xsl:value-of select="substring-after($text,'&#xA;')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
